;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014 Eric Bavier <address@hidden>
;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2022 jgart <jgart@dismail.de>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (guixrus packages jrnl)
  #:use-module (guix packages)
  #:use-module ((guix licenses) #:prefix license:)
  #:use-module (guix git-download)
  #:use-module (guix download)
  #:use-module (guix build-system python)
  #:use-module (gnu packages check)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages django)
  #:use-module (gnu packages freedesktop)
  #:use-module (gnu packages python)
  #:use-module (gnu packages python-build)
  #:use-module (gnu packages python-crypto)
  #:use-module (gnu packages python-xyz)
  #:use-module (gnu packages time)
  #:use-module ((guixrus licenses) #:prefix license:))

(define-public jrnl
  (package
    (name "jrnl")
    (version "2.8.4")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/jrnl-org/jrnl")
             (commit (string-append "v" version))))
       (file-name (git-file-name name version))
       (sha256
        (base32 "0iqcycqb3xryw35d76qvqqy1b1gibyfx3y8ys5mixyf3dwcvxnqi"))))
    (build-system python-build-system)
    (arguments
     `(#:tests? #f
       #:phases
       (modify-phases %standard-phases
         (replace 'build
           (lambda _
             (invoke "python" "-m" "build" "--wheel" "--no-isolation" ".")))
         (replace 'install
           (lambda* (#:key outputs #:allow-other-keys)
             (let ((out (assoc-ref outputs "out"))
                   (whl (car (find-files "dist" "\\.whl$"))))
               (invoke "pip" "--no-cache-dir" "--no-input"
                       "install" "--no-deps" "--prefix" out whl))))
         (replace 'check
           (lambda* (#:key tests? inputs outputs #:allow-other-keys)
             (when tests?
               (let ((bin (string-append (assoc-ref outputs "out") "/bin")))
                 (setenv "PATH" (string-append (getenv "PATH") ":" bin)))
               (add-installed-pythonpath inputs outputs)
               (invoke "pytest" "-vv")))))))
    (native-inputs
         (list python-poetry-core
               python-pypa-build
               ;python-pytest-bdd ; tests are failing
               python-toml
               python-pytest))
    (inputs
     (list python
           python-ansiwrap
           python-asteval
           python-colorama
           python-cryptography
           python-keyring
           python-parsedatetime
           python-dateutil
           python-pytz
           python-pyxdg
           python-pyyaml
           python-tzlocal))
    (home-page "https://jrnl.sh/")
    (synopsis "Personal journal application")
    (description
     "Jrnl is a command line journal application that stores your journal in a
plain text file.  Optionally, your journal can be encrypted using 256-bit AES
encryption.")
    (license license:gpl3+)))

(define-public python-textwrap3
  (package
    (name "python-textwrap3")
    (version "0.9.2")
    (source (origin
              (method url-fetch)
              (uri (pypi-uri "textwrap3" version ".zip"))
              (sha256
               (base32
                "051l1h7f8xdwfjx55n8iflczcmfkasw1i3ynvh1n6vr3vgmyw22h"))))
    (build-system python-build-system)
    (arguments
     `(#:tests? #f))
    (native-inputs (list unzip))
    (home-page "https://github.com/jonathaneunice/textwrap3")
    (synopsis "textwrap from Python 3.6 backport (plus a few tweaks)")
    (description "textwrap from Python 3.6 backport (plus a few tweaks)")
    (license license:none)))

(define-public python-ansiwrap
  (package
    (name "python-ansiwrap")
    (version "0.8.4")
    (source (origin
              (method url-fetch)
              (uri (pypi-uri "ansiwrap" version ".zip"))
              (sha256
               (base32
                "1dyrm0gd14s8x7pn1p4ch5ls7ybldww2rzzq37wrprfd6h3p836a"))))
    (build-system python-build-system)
    (arguments
     `(#:tests? #f))
    (propagated-inputs (list python-textwrap3))
    (native-inputs (list unzip))
    (home-page "https://github.com/jonathaneunice/ansiwrap")
    (synopsis "textwrap, but savvy to ANSI colors and styles")
    (description "textwrap, but savvy to ANSI colors and styles")
    (license license:none)))

(define-public python-pytest-bdd
  (package
    (name "python-pytest-bdd")
    (version "5.0.0")
    (source (origin
              (method url-fetch)
              (uri (pypi-uri "pytest-bdd" version))
              (sha256
               (base32
                "1krr58mcx499icc4m9frbcsdwh2g1v4r7q4dqvh1xrfmscz0kdzs"))))
    (build-system python-build-system)
    (propagated-inputs (list python-glob2
                             python-mako
                             python-parse
                             python-parse-type
                             python-py
                             python-pytest))
    (home-page "https://github.com/pytest-dev/pytest-bdd")
    (synopsis "BDD for pytest")
    (description "BDD for pytest")
    (license license:expat)))

(define-public python-jedi
  (package
    (name "python-jedi")
    (version "0.18.1")
    (source
     (origin
       (method git-fetch)
       (uri (git-reference
             (url "https://github.com/davidhalter/jedi")
             (commit (string-append "v" version))
             (recursive? #true)))
       (file-name (git-file-name name version))
       (sha256
        (base32
         "07drmi3ai49jw5n23ibkambcgijqcw073ihypjgxfnks5lv4yqy1"))))
    (build-system python-build-system)
    (arguments
     `(#:tests? #f
       #:phases
       (modify-phases %standard-phases
         (replace 'check
           (lambda* (#:key tests? #:allow-other-keys)
             (when tests?
               (setenv "HOME" "/tmp")
               (invoke "python" "-m" "pytest" "-vv")))))))
    (native-inputs
     (list python-colorama python-docopt python-pytest python-django-3.1.14))
    (propagated-inputs
     (list python-parso))
    (home-page "https://github.com/davidhalter/jedi")
    (synopsis "Autocompletion and static analysis library for Python")
    (description
     "Jedi is a static analysis tool for Python that can be used in Integrated
Development Environments (@dfn{IDE}s) and text editors.  It understands Python
on a deeper level than many other static analysis frameworks for Python.

Jedi understands docstrings and you can use Jedi autocompletion in your REPL
as well.")
    (license license:expat)))
